package com.thjk.bdf.common.base;

import java.io.Serializable;

import com.thjk.bdf.common.enmus.ServiceEnum;

public class BasicResp implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String code;

	private String message;

	public BasicResp() {
	}

	public BasicResp(String code, String message) {
		this.code = code;
		this.message = message;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	/**
	 * 
	 * @Description: 正常返回
	 * @params:参宿说明
	 */
	public static BasicResp back(String code, Object msg) {
		BasicResp json = new BasicResp();
		json.setCode(code);
		json.setMessage(msg == null ? "" : msg.toString());
		return json;
	}

	/**
	 * 
	 * @Description: 默认成功返回
	 * @params:成功
	 */
	public static BasicResp success() {
		BasicResp json = new BasicResp();
		json.setCode(ServiceEnum.SERVICE_SUCCESS.getCode());
		json.setMessage(ServiceEnum.SERVICE_SUCCESS.getDesc());
		return json;
	}

	public static boolean isSuccess(BasicResp basicResp) {
		if (basicResp.getCode() != null && ServiceEnum.SERVICE_SUCCESS.getCode().equals(basicResp.getCode())) {
			return true;
		}
		return false;

	}

	public static BasicResp error() {
		BasicResp json = new BasicResp();
		json.setCode(ServiceEnum.SERVICE_FAIL.getCode());
		json.setMessage(ServiceEnum.SERVICE_FAIL.getDesc());
		return json;
	}

	@Override
	public String toString() {
		return "BasicResp [code=" + code + ", message=" + message + "]";
	}

}
